﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Drawing;

namespace Sunboxsoft.WinForm.Shell
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //DevExpress.Utils.AppearanceObject.DefaultFont = new Font("微软雅黑", 12);

            LaunchForm launchForm = new LaunchForm();
            if (launchForm.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            IModule selectedModule = null;
            if (Common.RuntimeData.Instance.ModuleInstanceArray.Length > 1)
            {
                SwitchModuleForm switchModuleForm = new SwitchModuleForm();
                if (switchModuleForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                selectedModule = switchModuleForm.SelectedModule;
            }
            else
            {
                selectedModule = Common.RuntimeData.Instance.ModuleInstanceArray.First();
            }

            if (selectedModule is IStandalone)
            {
                if ((selectedModule as IStandalone).Run() == false)
                {
                    return;
                }
            }
            else
            {
                if (new LaunchModuleForm(selectedModule).ShowDialog() != DialogResult.OK)
                {
                    return;
                }
            }

            Application.Run(new MainForm(selectedModule));
        }
    }
}
